/**
 * 时间 ： 2014-6-3 上午11:08:56
 * 作者 ： HaiTao
 * 描述 ： 当前类的描述信息
 **/
package com.laitaoo.service.home
{
	import com.laitaoo.event.KindsEvent;
	import com.laitaoo.service.BaseService;
	import com.maclema.mysql.MySqlResponse;
	import com.maclema.mysql.MySqlToken;
	import com.maclema.mysql.ResultSet;
	
	import flash.media.Video;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.AsyncResponder;
	
	[RouteEvents(events="allKindsResult,insertKindResult,updateKindResult")]
	[Component]
	public class KindService extends BaseService
	{
		public function KindService()
		{
			super();
		}
		/**
		 * 获取所有分类
		 **/
		public function getKinds():void{
			
			getKindList(kindsResultHandler,kindsFaultHandler);
		}
		private function kindsResultHandler(data:Object, token:Object):void{
			
			var rs:ResultSet = ResultSet(data);
			
			// 派发加载导航树的事件
			var kindEvent:KindsEvent= new KindsEvent(KindsEvent.ALL_KINDS_RESULT);
			kindEvent.kinds = rs.getRows() as ArrayCollection;
			dispatchEvent(kindEvent);
		}
		
		private function kindsFaultHandler(info:Object, token:Object):void{
		}
		// =================================
		
		public function insertKind(kindObj:Object):void{
			
			var sql:String = "insert into kinds(kindName,commont) values ('"+kindObj.kindName+"','"+kindObj.commont+"')";
			
			var token:MySqlToken = st.executeQuery(sql);
			
			token.addResponder(new AsyncResponder(insertKindResultHandler,insertKindFaultHandler,token));
		}
		private function insertKindResultHandler(data:Object, token:Object):void{
			
			var rs:MySqlResponse = MySqlResponse(data);
			
			// 派发加载导航树的事件
			var kindEvent:KindsEvent= new KindsEvent(KindsEvent.INSERT_KIND_RESULT);
			dispatchEvent(kindEvent); 
		}
		private function insertKindFaultHandler(info:Object, token:Object):void{
		}
		// ========
		
		public function updateKind(obj:Object):void{
			
			var sql:String = "update kinds set kindName='"+obj.kindName+"',commont='"+obj.commont+"' where Id='"+obj.Id+"'";
			
			var token:MySqlToken = st.executeQuery(sql);
			
			token.addResponder(new AsyncResponder(updateKindResultHandler,updateKindFaultHandler,token));
		}
		private function updateKindResultHandler(data:Object, token:Object):void{
			
			var rs:MySqlResponse = MySqlResponse(data);
			
			// 派发加载导航树的事件
			var kindEvent:KindsEvent= new KindsEvent(KindsEvent.UPDATE_KIND_RESULT);
			dispatchEvent(kindEvent); 
		}
		private function updateKindFaultHandler(info:Object, token:Object):void{
		}
	}
}